#ifndef GP_MM_H
#define GP_MM_H

#ifdef GP_MM_COMPRESSED_H
#error "Only one of mm.h and mm_compressed.h can be included at a time!"
#endif //GP_MM_COMPRESSED_H

/**
  * sections
  */

#define GP_MM_FLASH_START 0x4000000
#define GP_MM_FLASH_END   0x4800000
#define GP_MM_FLASH_SIZE  0x800000

#define GP_MM_FLASH_ALT_START 0x4200000
#define GP_MM_FLASH_ALT_END   0x4300000
#define GP_MM_FLASH_ALT_SIZE  0x100000

#define GP_MM_FLASH_VIRT_WINDOWS_START 0x4400000
#define GP_MM_FLASH_VIRT_WINDOWS_END   0x4500000
#define GP_MM_FLASH_VIRT_WINDOWS_SIZE  0x100000

#define GP_MM_ROM_START 0x4800000
#define GP_MM_ROM_END   0x5000000
#define GP_MM_ROM_SIZE  0x800000

#define GP_MM_RAM_START 0x20000000
#define GP_MM_RAM_END   0x20040000
#define GP_MM_RAM_SIZE   0x40000

#define GP_MM_UCRAM_START 0x20040000
#define GP_MM_UCRAM_END   0x20080000
#define GP_MM_UCRAM_SIZE   0x40000

#define GP_MM_AHB_START 0x20100000
#define GP_MM_AHB_END   0x20140000
#define GP_MM_AHB_SIZE   0x40000

#define GP_MM_RAM_BITBAND_START 0x22000000
#define GP_MM_RAM_BITBAND_END   0x24000000
#define GP_MM_RAM_BITBAND_SIZE  0x2000000

#define GP_MM_WISHB_START 0x40000000
#define GP_MM_WISHB_END   0x42000000
#define GP_MM_WISHB_SIZE  0x2000000

#define GP_MM_WISHB_BITBAND_START 0x42000000
#define GP_MM_WISHB_BITBAND_END   0x44000000
#define GP_MM_WISHB_BITBAND_SIZE  0x2000000


/**
  * compressed section address translation
  */

#define GP_MM_FLASH_COMPRESSED_START 0x200000
#define GP_MM_FLASH_ALT_COMPRESSED_START 0x200000
#define GP_MM_FLASH_VIRT_WINDOWS_COMPRESSED_START 0x300000
#define GP_MM_ROM_COMPRESSED_START 0x400000
#define GP_MM_RAM_COMPRESSED_START 0x0C0000
#define GP_MM_UCRAM_COMPRESSED_START 0x100000
#define GP_MM_AHB_COMPRESSED_START 0x140000
#define GP_MM_RAM_BITBAND_COMPRESSED_START 0x22000000
#define GP_MM_WISHB_COMPRESSED_START 0x000000
#define GP_MM_WISHB_BITBAND_COMPRESSED_START 0x42000000

/* translate from own address to compressed address */
#define GP_MM_FLASH_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_FLASH_START + 0x200000)
#define GP_MM_FLASH_ALT_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_FLASH_ALT_START + 0x200000)
#define GP_MM_FLASH_VIRT_WINDOWS_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_FLASH_VIRT_WINDOWS_START + 0x300000)
#define GP_MM_ROM_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_ROM_START + 0x400000)
#define GP_MM_RAM_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_RAM_START + 0x0C0000)
#define GP_MM_UCRAM_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_UCRAM_START + 0x100000)
#define GP_MM_AHB_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_AHB_START + 0x140000)
#define GP_MM_RAM_BITBAND_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_RAM_BITBAND_START + 0x22000000)
#define GP_MM_WISHB_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_WISHB_START + 0x000000)
#define GP_MM_WISHB_BITBAND_ADDR_TO_COMPRESSED(addr) ((addr) - GP_MM_WISHB_BITBAND_START + 0x42000000)

/* translate compressed address to own address */
#define GP_MM_FLASH_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x200000 + GP_MM_FLASH_START)
#define GP_MM_FLASH_ALT_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x200000 + GP_MM_FLASH_ALT_START)
#define GP_MM_FLASH_VIRT_WINDOWS_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x300000 + GP_MM_FLASH_VIRT_WINDOWS_START)
#define GP_MM_ROM_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x400000 + GP_MM_ROM_START)
#define GP_MM_RAM_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x0C0000 + GP_MM_RAM_START)
#define GP_MM_UCRAM_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x100000 + GP_MM_UCRAM_START)
#define GP_MM_AHB_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x140000 + GP_MM_AHB_START)
#define GP_MM_RAM_BITBAND_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x22000000 + GP_MM_RAM_BITBAND_START)
#define GP_MM_WISHB_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x000000 + GP_MM_WISHB_START)
#define GP_MM_WISHB_BITBAND_ADDR_FROM_COMPRESSED(addr) ((addr) - 0x42000000 + GP_MM_WISHB_BITBAND_START)

/**
 * areas
 */

#define GP_MM_FLASH_LINEAR_START  0x4000000
#define GP_MM_FLASH_LINEAR_END    0x4100000
#define GP_MM_FLASH_LINEAR_SIZE    0x100000

#define GP_MM_FLASH_REDUNDANT_0_START  0x4100000
#define GP_MM_FLASH_REDUNDANT_0_END    0x4100400
#define GP_MM_FLASH_REDUNDANT_0_SIZE       0x400

#define GP_MM_FLASH_REDUNDANT_1_START  0x4100400
#define GP_MM_FLASH_REDUNDANT_1_END    0x4100800
#define GP_MM_FLASH_REDUNDANT_1_SIZE       0x400

#define GP_MM_FLASH_REDUNDANT_2_START  0x4100800
#define GP_MM_FLASH_REDUNDANT_2_END    0x4100C00
#define GP_MM_FLASH_REDUNDANT_2_SIZE       0x400

#define GP_MM_FLASH_REDUNDANT_3_START  0x4100C00
#define GP_MM_FLASH_REDUNDANT_3_END    0x4101000
#define GP_MM_FLASH_REDUNDANT_3_SIZE       0x400

#define GP_MM_FLASH_NVR_PAGE_START  0x4180000
#define GP_MM_FLASH_NVR_PAGE_END    0x4180400
#define GP_MM_FLASH_NVR_PAGE_SIZE       0x400

#define GP_MM_FLASH_NVR_SECT_0_START  0x4180000
#define GP_MM_FLASH_NVR_SECT_0_END    0x4180400
#define GP_MM_FLASH_NVR_SECT_0_SIZE       0x400

#define GP_MM_FLASH_NVR_NOT_READABLE_START  0x4180140
#define GP_MM_FLASH_NVR_NOT_READABLE_END    0x4180200
#define GP_MM_FLASH_NVR_NOT_READABLE_SIZE        0xC0

#define GP_MM_FLASH_NVR_USER_KEY_NOT_READABLE_START  0x4180200
#define GP_MM_FLASH_NVR_USER_KEY_NOT_READABLE_END    0x4180280
#define GP_MM_FLASH_NVR_USER_KEY_NOT_READABLE_SIZE        0x80

#define GP_MM_FLASH_NVR_SECT_1_START  0x4180800
#define GP_MM_FLASH_NVR_SECT_1_END    0x4180C00
#define GP_MM_FLASH_NVR_SECT_1_SIZE       0x400

#define GP_MM_FLASH_NVR_CFG_PAGE_START  0x41C0000
#define GP_MM_FLASH_NVR_CFG_PAGE_END    0x41C0200
#define GP_MM_FLASH_NVR_CFG_PAGE_SIZE       0x200

#define GP_MM_FLASH_NVR_CFG_RECORD_START  0x41FFF80
#define GP_MM_FLASH_NVR_CFG_RECORD_END    0x4200000
#define GP_MM_FLASH_NVR_CFG_RECORD_SIZE        0x80

#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_0_START  0x4400000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_0_END    0x4401000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_0_SIZE      0x1000

#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_1_START  0x4401000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_1_END    0x4402000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_1_SIZE      0x1000

#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_2_START  0x4402000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_2_END    0x4403000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_2_SIZE      0x1000

#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_3_START  0x4403000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_3_END    0x4404000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_3_SIZE      0x1000

#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_4_START  0x4404000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_4_END    0x4405000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_4_SIZE      0x1000

#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_5_START  0x4405000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_5_END    0x4406000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_5_SIZE      0x1000

#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_6_START  0x4406000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_6_END    0x4407000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_6_SIZE      0x1000

#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_7_START  0x4407000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_7_END    0x4408000
#define GP_MM_FLASH_VIRT_WINDOWS_FLASH_VIRT_WINDOW_7_SIZE      0x1000

#define GP_MM_ROM_LINEAR_START  0x4800000
#define GP_MM_ROM_LINEAR_END    0x4840000
#define GP_MM_ROM_LINEAR_SIZE     0x40000

#define GP_MM_ROM_SECURITY_REGION_LOWER_START  0x483FF00
#define GP_MM_ROM_SECURITY_REGION_LOWER_END    0x4840F00
#define GP_MM_ROM_SECURITY_REGION_LOWER_SIZE      0x1000

#define GP_MM_ROM_SECURITY_REGION_UPPER_START  0x483FF80
#define GP_MM_ROM_SECURITY_REGION_UPPER_END    0x4840F80
#define GP_MM_ROM_SECURITY_REGION_UPPER_SIZE      0x1000

#define GP_MM_RAM_MAGIC_WORD_START  0x20038000
#define GP_MM_RAM_MAGIC_WORD_END    0x20038004
#define GP_MM_RAM_MAGIC_WORD_SIZE          0x4

#define GP_MM_RAM_CRC_START  0x20038004
#define GP_MM_RAM_CRC_END    0x20038008
#define GP_MM_RAM_CRC_SIZE          0x4

#define GP_MM_RAM_RETENTION_START  0x20038008
#define GP_MM_RAM_RETENTION_END    0x200381BC
#define GP_MM_RAM_RETENTION_SIZE        0x1B4

#define GP_MM_RAM_GPMICRO_RAM_START  0x20038008
#define GP_MM_RAM_GPMICRO_RAM_END    0x200380C0
#define GP_MM_RAM_GPMICRO_RAM_SIZE         0xB8

#define GP_MM_RAM_GPMICRO_STACK_START  0x200380C0
#define GP_MM_RAM_GPMICRO_STACK_END    0x200381C0
#define GP_MM_RAM_GPMICRO_STACK_SIZE        0x100

#define GP_MM_RAM_PKEY_START  0x20038380
#define GP_MM_RAM_PKEY_END    0x20038400
#define GP_MM_RAM_PKEY_SIZE         0x80

#define GP_MM_RAM_PUFR_START  0x20038400
#define GP_MM_RAM_PUFR_END    0x20038800
#define GP_MM_RAM_PUFR_SIZE        0x400

#define GP_MM_AHB_CRYPTOMASTER_DMA_START  0x20100000
#define GP_MM_AHB_CRYPTOMASTER_DMA_END    0x20101000
#define GP_MM_AHB_CRYPTOMASTER_DMA_SIZE       0x1000

#define GP_MM_AHB_RNG_CONTROL_REG_START  0x20101000
#define GP_MM_AHB_RNG_CONTROL_REG_END    0x20102000
#define GP_MM_AHB_RNG_CONTROL_REG_SIZE       0x1000

#define GP_MM_AHB_PUBLIC_KEY_REG_START  0x20102000
#define GP_MM_AHB_PUBLIC_KEY_REG_END    0x20103000
#define GP_MM_AHB_PUBLIC_KEY_REG_SIZE       0x1000

#define GP_MM_AHB_RNG_OUTPUT_START  0x20104000
#define GP_MM_AHB_RNG_OUTPUT_END    0x20108000
#define GP_MM_AHB_RNG_OUTPUT_SIZE       0x4000

#define GP_MM_AHB_PUBLIC_KEY_DATARAM_START  0x20108000
#define GP_MM_AHB_PUBLIC_KEY_DATARAM_END    0x2010C000
#define GP_MM_AHB_PUBLIC_KEY_DATARAM_SIZE       0x4000

#define GP_MM_AHB_PUBLIC_KEY_CODEROM_START  0x2010C000
#define GP_MM_AHB_PUBLIC_KEY_CODEROM_END    0x20110000
#define GP_MM_AHB_PUBLIC_KEY_CODEROM_SIZE       0x4000


/**
 * windows
 */

#define GP_MM_RAM_PBM_OPTS_START  0x20002000
#define GP_MM_RAM_PBM_OPTS_END    0x20002020
#define GP_MM_RAM_PBM_OPTS_SIZE         0x20
#define GP_MM_RAM_PBM_OPTS_OFFSET 0x00000020
#define GP_MM_RAM_PBM_OPTS_NR_OF  32

#define GP_MM_RAM_EVENT_START  0x20002400
#define GP_MM_RAM_EVENT_END    0x20002410
#define GP_MM_RAM_EVENT_SIZE         0x10
#define GP_MM_RAM_EVENT_OFFSET 0x00000010
#define GP_MM_RAM_EVENT_NR_OF  16

#define GP_MM_RAM_RAM_REGMAP_START  0x20002600
#define GP_MM_RAM_RAM_REGMAP_END    0x20002800
#define GP_MM_RAM_RAM_REGMAP_SIZE        0x200

#define GP_MM_RAM_CIRC_WINDOW_LEFT_0_START  0x20002800
#define GP_MM_RAM_CIRC_WINDOW_LEFT_0_END    0x20002880
#define GP_MM_RAM_CIRC_WINDOW_LEFT_0_SIZE         0x80

#define GP_MM_RAM_CIRC_WINDOW_RIGHT_0_START  0x20002880
#define GP_MM_RAM_CIRC_WINDOW_RIGHT_0_END    0x20002900
#define GP_MM_RAM_CIRC_WINDOW_RIGHT_0_SIZE         0x80

#define GP_MM_RAM_PBM_0_DATA_START  0x20004000
#define GP_MM_RAM_PBM_0_DATA_END    0x20004200
#define GP_MM_RAM_PBM_0_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_1_DATA_START  0x20004200
#define GP_MM_RAM_PBM_1_DATA_END    0x20004400
#define GP_MM_RAM_PBM_1_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_2_DATA_START  0x20004400
#define GP_MM_RAM_PBM_2_DATA_END    0x20004600
#define GP_MM_RAM_PBM_2_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_3_DATA_START  0x20004600
#define GP_MM_RAM_PBM_3_DATA_END    0x20004800
#define GP_MM_RAM_PBM_3_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_4_DATA_START  0x20004800
#define GP_MM_RAM_PBM_4_DATA_END    0x20004A00
#define GP_MM_RAM_PBM_4_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_5_DATA_START  0x20004A00
#define GP_MM_RAM_PBM_5_DATA_END    0x20004C00
#define GP_MM_RAM_PBM_5_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_6_DATA_START  0x20004C00
#define GP_MM_RAM_PBM_6_DATA_END    0x20004E00
#define GP_MM_RAM_PBM_6_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_7_DATA_START  0x20004E00
#define GP_MM_RAM_PBM_7_DATA_END    0x20005000
#define GP_MM_RAM_PBM_7_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_8_DATA_START  0x20005000
#define GP_MM_RAM_PBM_8_DATA_END    0x20005200
#define GP_MM_RAM_PBM_8_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_9_DATA_START  0x20005200
#define GP_MM_RAM_PBM_9_DATA_END    0x20005400
#define GP_MM_RAM_PBM_9_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_10_DATA_START  0x20005400
#define GP_MM_RAM_PBM_10_DATA_END    0x20005600
#define GP_MM_RAM_PBM_10_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_11_DATA_START  0x20005600
#define GP_MM_RAM_PBM_11_DATA_END    0x20005800
#define GP_MM_RAM_PBM_11_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_12_DATA_START  0x20005800
#define GP_MM_RAM_PBM_12_DATA_END    0x20005A00
#define GP_MM_RAM_PBM_12_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_13_DATA_START  0x20005A00
#define GP_MM_RAM_PBM_13_DATA_END    0x20005C00
#define GP_MM_RAM_PBM_13_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_14_DATA_START  0x20005C00
#define GP_MM_RAM_PBM_14_DATA_END    0x20005E00
#define GP_MM_RAM_PBM_14_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_15_DATA_START  0x20005E00
#define GP_MM_RAM_PBM_15_DATA_END    0x20006000
#define GP_MM_RAM_PBM_15_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_16_DATA_START  0x20006000
#define GP_MM_RAM_PBM_16_DATA_END    0x20006200
#define GP_MM_RAM_PBM_16_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_17_DATA_START  0x20006200
#define GP_MM_RAM_PBM_17_DATA_END    0x20006400
#define GP_MM_RAM_PBM_17_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_18_DATA_START  0x20006400
#define GP_MM_RAM_PBM_18_DATA_END    0x20006600
#define GP_MM_RAM_PBM_18_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_19_DATA_START  0x20006600
#define GP_MM_RAM_PBM_19_DATA_END    0x20006800
#define GP_MM_RAM_PBM_19_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_20_DATA_START  0x20006800
#define GP_MM_RAM_PBM_20_DATA_END    0x20006A00
#define GP_MM_RAM_PBM_20_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_21_DATA_START  0x20006A00
#define GP_MM_RAM_PBM_21_DATA_END    0x20006C00
#define GP_MM_RAM_PBM_21_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_22_DATA_START  0x20006C00
#define GP_MM_RAM_PBM_22_DATA_END    0x20006E00
#define GP_MM_RAM_PBM_22_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_23_DATA_START  0x20006E00
#define GP_MM_RAM_PBM_23_DATA_END    0x20007000
#define GP_MM_RAM_PBM_23_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_24_DATA_START  0x20007000
#define GP_MM_RAM_PBM_24_DATA_END    0x20007200
#define GP_MM_RAM_PBM_24_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_25_DATA_START  0x20007200
#define GP_MM_RAM_PBM_25_DATA_END    0x20007400
#define GP_MM_RAM_PBM_25_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_26_DATA_START  0x20007400
#define GP_MM_RAM_PBM_26_DATA_END    0x20007600
#define GP_MM_RAM_PBM_26_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_27_DATA_START  0x20007600
#define GP_MM_RAM_PBM_27_DATA_END    0x20007800
#define GP_MM_RAM_PBM_27_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_28_DATA_START  0x20007800
#define GP_MM_RAM_PBM_28_DATA_END    0x20007A00
#define GP_MM_RAM_PBM_28_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_29_DATA_START  0x20007A00
#define GP_MM_RAM_PBM_29_DATA_END    0x20007C00
#define GP_MM_RAM_PBM_29_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_30_DATA_START  0x20007C00
#define GP_MM_RAM_PBM_30_DATA_END    0x20007E00
#define GP_MM_RAM_PBM_30_DATA_SIZE        0x200

#define GP_MM_RAM_PBM_31_DATA_START  0x20007E00
#define GP_MM_RAM_PBM_31_DATA_END    0x20008000
#define GP_MM_RAM_PBM_31_DATA_SIZE        0x200

#define GP_MM_RAM_LINEAR_START  0x20038000
#define GP_MM_RAM_LINEAR_END    0x20040000
#define GP_MM_RAM_LINEAR_SIZE       0x8000

#define GP_MM_UCRAM_LINEAR_START  0x20040000
#define GP_MM_UCRAM_LINEAR_END    0x20058000
#define GP_MM_UCRAM_LINEAR_SIZE      0x18000


#endif //GP_MM_H


